package com.st.task;

import com.api.attractions.IAttractionsClient;
import com.api.scenic.IScenicClient;
import com.jwt.util.JsonUtils;
import com.st.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


@Component
public class ContentTask {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private IScenicClient iScenicClient;
    @Autowired
    private IAttractionsClient iAttractionsClient;
    @Scheduled(cron = "10 22 * * * *")
    public void saveContent(){
        Result content = iScenicClient.content();
        Object contents =  content.getData();
        if (contents == null) {
            return;
        }
        String contentsStr = JsonUtils.toString(contents);
        stringRedisTemplate.boundValueOps("lunbotu").set(contentsStr);
    }
    @Scheduled(cron = "10 22 * * * *")
    public void saveHot() {
        Result attractions = iAttractionsClient.saveHot();
        Object data = attractions.getData();
        if (data == null) {
            return;
        }
        String attractionsStr = JsonUtils.toString(data);
        stringRedisTemplate.boundValueOps("hot").set(attractionsStr);
    }











}
